﻿
"use strict";
angular.module('app.project').controller('MyAllProjectCtrl', function ($scope,personalCenterHttp, projectHttpS,jurisHttpS, 
		$http,$rootScope, $stateParams,$cookieStore) {

    $scope.paginationConf = {
        currentPage: 1,
        itemsPerPage: 100,
        pagesLength: 5,
        totalItems: 20,
        perPageOptions: [10, 20, 30, 40, 50],
        plan: 0,
        onChange: function () {
        }
    };
    

    // 回退清空全局id
    $rootScope.Edit_pro_id = null;

    //判断权限
    $scope.status = true;
    $scope.visible = true;


    $scope.createProject = function () {

        window.location.href = appConfig.base[0].baseURI + "#/add_newProject";

    }
    
    var getData = function(){
        //获得项目数据
        var user_id = $cookieStore.get("user_id");
        $http.get('api/project.json').then(function(res){
            var arr = [];
            if(user_id == 1){//超级管理员
                arr = res.data;
            }else{
                for(var i=0;i<res.data.length;i++){
                    if(res.data[i].fid == user_id){
                        arr.push(res.data[i]);
                    }else{
                        
                    }
                }
            }
            $scope.projects = arr;
            // console.log($scope.projects);
        })
    };
    getData();
    $scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage',getData);


    $scope.tomypro = function(proid){//没用
        $cookieStore.put('project_id',proid);
    	  //？
    	//   window.location.href = appConfig.base[0].baseURI + "#/granary/granaryDetail";
    };

    // 项目编辑
    $scope.Edit_pro = function(id){
        $rootScope.Edit_pro_id = id;
        window.location.href = appConfig.base[0].baseURI + "#/add_newProject";//编辑项目
        console.log($rootScope.Edit_pro_id)
    };
    
    


});